<?php

namespace app\common\model;

use think\Model;


class Invoice extends Model
{

    

    

    // 表名
    protected $name = 'invoice';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'type_text',
        'class_text',
        'rise_text',
        'state_text',
        'status_text',
        'maketime_text',
        'createtime_text',
    ];
    

    
    public function getTypeList()
    {
        return ['1' => __('Type 1')];
    }

    public function getClassList()
    {
        return ['1' => __('Class 1'), '2' => __('Class 2')];
    }

    public function getRiseList()
    {
        return ['1' => __('Rise 1'), '2' => __('Rise 2')];
    }

    public function getStateList()
    {
        return ['1' => __('State 1'), '2' => __('State 2')];
    }

    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2')];
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getClassTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['class']) ? $data['class'] : '');
        $list = $this->getClassList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getRiseTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['rise']) ? $data['rise'] : '');
        $list = $this->getRiseList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStateTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['state']) ? $data['state'] : '');
        $list = $this->getStateList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getCreatetimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['createtime']) ? $data['createtime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    public function getMaketimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['maketime']) ? $data['maketime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setMaketimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


}
